
use global_BLAs_09_21_21, clear

merge 1:1 ID using bla_coding_first_09_27_21.dta

keep if _merge==3

/*Confirming the data are correct

gen data_correct = 1 if (countryA==coded_countryA & countryB==coded_countryB | countryA==coded_countryB & countryB==coded_countryA) & year==coded_year
replace data_correct = 0 if data_correct==. & _merge==3

browse ID countryA countryB year coded_countryA coded_countryB coded_year agreement_title ///
	if data_correct==0

*/

gen governance_title  = 0, b(intl_instr)
lab var governance_title "{bf:Governance of Labor Migration}"

gen protection_title = 0, b(migrant_info)
lab var protection_title "{bf:Protection and Empowerment of Migrant Workers}"
gen protection_space = 0, b(protection_title)
lab var protection_space " "

gen dev_title = 0, b(mig_human_cap)
lab var dev_title "{bf:Migration and Development}"
gen dev_space = 0, b(dev_title)
lab var dev_space " "

vl create barvars = (governance_title-recruit_auth labor_union_orig-perm_resid)

vl create barvars1 = (intl_instr-recruit_auth labor_union_orig-ngos)
vl create barvars2 = (migrant_info-disputes_emp_mig)
vl create barvars3 = (mig_human_cap-perm_resid)



*3) provision by year

foreach var in $barvars{
 
	local lab`var' "`:var lab `var''"
	
}

collapse (sum) $barvars (count) ID, by(year)

drop if year<1945

foreach var in $barvars{
 
	lab var `var' "`lab`var''"
	
}

sort year
gen sum_tot = sum(ID)
foreach var in $barvars{
 
	gen sum_`var' = sum(`var')
	gen cshare_`var' = sum_`var'/sum_tot
	
}

order cshare*, last

vl create cshbarvars1 = (cshare_intl_instr-cshare_ngos)
vl create cshbarvars2 = (cshare_migrant_info-cshare_disputes_emp_mig)
vl create cshbarvars3 = (cshare_mig_human_cap-cshare_perm_resid)


*Create Graphs

foreach var in $barvars{

	#delimit ;
	
	twoway line cshare_`var' year, lc(black) xlab(#16, angle(45) labsize(*0.55)) ylab(0(0.2)1, angle(0))
		title("`:var lab `var''", size(*0.4)) graphregion(color(white)) name(`var', replace)
		yt("") xt("");
	
	#delimit cr
	
}

graph combine $barvars1, graphregion(color(white)) name(governance_lines, replace)

graph combine $barvars2, graphregion(color(white)) name(protection_lines, replace)

graph combine $barvars3, graphregion(color(white)) name(development_lines, replace)
